﻿using BasicDemo.ch3;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Web;

namespace BasicDemo
{
    public class Program
    {
        public static void Main(string[] args)
        {
            sbyte b = 111;
            long i = 11111111111111;

            double d = 1.23;
            float f = 1.23F;
            decimal c = 1.23M;
            Console.WriteLine(i);

            string s = @"c:\data\log";
            string s1 = $"f.value is {f}";
            string s2 = @"<html></html>";
            Console.WriteLine(s);
            Console.WriteLine(s1);
            Console.WriteLine(s2);

            Console.WriteLine("b.value is {0}", b);

            RunDemo.TestStruct();

            DateTime dt = DateTime.Now;
            string dtstr = dt.ToString("yyyy-MM-dd HH:mm:ss");
            Console.WriteLine(dtstr);

            DateTime dt2 = new DateTime(2023, 5, 16);
            Console.WriteLine(dt2.ToString("yyyy-MM-dd"));

            DateTime cd = Convert.ToDateTime("2023-05-09 12:45:09");
            Console.WriteLine(cd.ToString("yyyy-MM-dd HH:mm:ss"));

            Console.WriteLine(Add(2));

            var person = new
            {
                Name = "huyucai",
                Gender = "男",
                Age = 20
            };
            Console.WriteLine(person.Name);

            Console.WriteLine(Add(10,1,2,3,4));
            Console.WriteLine(Add(10,new int[]{ 1,2,3}));

            Console.WriteLine(default(decimal));

            int a = 1;
            ChangeInt(ref a);
            Console.WriteLine("a=" + a);

            Person p = new Person(1);
            Console.WriteLine(p.GetHashCode());
            ChangePerson(ref p);
            Console.WriteLine(p.GetHashCode());
            Console.WriteLine("person.id的值为:" + p.Id);

            string va = "12";
            StrToInt(va, out int res);
            Console.WriteLine($"res={res},type={res.GetType()}");

            ArrayList al = new ArrayList();// 非泛型集合
            al.Add(1);// 装箱
            int il = (int)al[0];// 拆箱

            List<int> list = new List<int>();// 泛型集合，不存在装箱和拆箱
            list.Add(2);
            int il2 = list[0];

            int int1 = 1;
            int int2 = 2;
            Swap(ref int1, ref int2);
            Console.WriteLine($"int1={int1},int2={int2}");


            Console.ReadKey();
        }

        public static void ChangeInt(ref int x)
        {
            x = 2;
        }

        public static void ChangePerson(ref Person p)
        {
            Console.WriteLine(p.GetHashCode());
            p.Id = 2;
            p = new Person(3);
            Console.WriteLine(p.GetHashCode());
        }

        public static int Add(int x) => x + 1;

        public static int Add(int i, params int[] arr)
        {
            int result = i;
            foreach (int item in arr)
            {
                result += item;
            }
            return result;
        }

        public static void StrToInt(string s, out int res)
        {
            res = int.Parse(s);
        }

        public static void Swap<T>(ref T x, ref T y)
        {
            T temp;
            temp = x;
            x = y;
            y = temp;
        }
    }
}
